<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        if (!empty(cookie("username"))) {
            $this->redirect('Main/method_list', array(), 0);
        } else {
            $this->redirect('login', array(), 0);
        }
    }

    function login()
    {
        if (!empty($_POST)) {
            $password = md5($_POST['password']);
            $login = D('ssg_account');

            $is_exists =  $login->where("account='".$_POST['username']."' and password='".$password."' and roleId='".$_POST['role']."'");
            if($is_exists && $this->verify()){
                cookie("username", $_POST['username']);
                $this->redirect('Main/method_list', array(), 0);
            }else{

                dump("密码错误");
            }
        } else {
            $this->display();
        }
    }

    //输出验证码
    function verify()
    {
        $config = array(
            'imageH' => 0,
            'imageW' => 0,
            'fontSize' => 25,    // 验证码字体大小
            'length' => 4,     // 验证码位数
            'useNoise' => false, // 关闭验证码杂点
            'fontttf ' => '5.ttf',
            'codeSet' => '0123456789'
        );
        $Verify = new \Think\Verify($config);
        if (!empty($_POST['verify_number'])) {
            return $Verify->check($_POST['verify_number']);
        } else {
            $Verify->entry();
        }


    }
}
